package utils;

import cn.hutool.core.io.FileUtil;

import java.io.File;
import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * @Description: 纪录错误日志
 * @Author: syh
 * @Date: 2023/10/10/17:21
 */
public class ExceptionUtil {
    /**
     * 获取异常信息
     * @param e
     * @return
     */
    public static String writeLog(Exception e){
        //获取报错
        try(
                StringWriter writer = new StringWriter();
                PrintWriter printWriter = new PrintWriter(writer);
        ){
            //获取错误日志
            e.printStackTrace(printWriter);
            String errorLogPath = PathUtil.getErrorLogPath();
            FileUtil.writeString( writer.toString(),errorLogPath,"utf-8");
            return writer.toString();
        }catch (Exception exception){
            exception.printStackTrace();
        }

        return "";
    }
}
